package com.gzw.dms.activity;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;

import com.gzw.dms.BuildConfig;
import com.gzw.dms.MyApplication;
import com.gzw.dms.R;
import com.gzw.dms.base.BaseActivity;
import com.gzw.dms.base.BaseSpinnerAdapter;
import com.gzw.dms.bean.AbnormalReportInfo;
import com.gzw.dms.bean.ShippingOrderInfo;
import com.gzw.dms.bean.SingnInfo;
import com.gzw.dms.bean.SpinnerInfo;
import com.gzw.dms.bean.UserInfo;
import com.gzw.dms.utils.DateUtil;
import com.gzw.dms.utils.FileUtil;
import com.gzw.dms.utils.HttpUtils;
import com.gzw.dms.utils.JsonUtil;
import com.gzw.dms.utils.L;
import com.gzw.dms.utils.ScreenUtils;
import com.gzw.dms.utils.T;
import com.gzw.dms.utils.ToolFor9Ge;
import com.gzw.dms.utils.UrlUtils;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.finalteam.galleryfinal.CoreConfig;
import cn.finalteam.galleryfinal.FunctionConfig;
import cn.finalteam.galleryfinal.GalleryFinal;
import cn.finalteam.galleryfinal.ImageLoader;
import cn.finalteam.galleryfinal.ThemeConfig;
import cn.finalteam.galleryfinal.model.PhotoInfo;
import cn.finalteam.toolsfinal.StorageUtils;

public class UnusualActivity extends BaseActivity {
    private TextView tv_shiping_order_num, tv_custom_name, tv_custom_contact,
            tv_custom_tel, tv_receipt_name, tv_receipt_tel, tv_goods_name, tv_goods_num, tv_goods_weight,
            tv_goods_vol, tv_shipping_order_state, tv_is_recept, tv_remarks,tv_send_station
            ,tv_end_mechanism,tv_shiping_order_goid,tv_send_mechanism;
    private EditText ed_number,ed_name,ed_other,ed_remarks;
    private Button btn_edit;
    private Intent mIntent;
    private ShippingOrderInfo shippingOrder;
    private ProgressDialog mProgressDialog;
    private Context mContext;
    private Toolbar toolbar;
    //0、1为接单，2已接单，3电子围栏签收，4实际签收,5分配订单
    private  String state;
    private  String fpstste="0";
    private List<String> ls_map;
    private Spinner sp_identity,sp_reson;
    private String  type = "0";
    private ArrayList  ls2,ls3;
    private ImageView iv_uploading1,iv_uploading2,iv_uploading3,iv_uploading4,iv_uploading5,iv_uploading6;
    private String fileName4,fileName5,fileName6,reviewed_state,user_id;
    private String path;
    private int REQUEST_CODE_CAMERA=1;
    private  String fileRoot = "abnormalreport";
    private int imgH = 800;
    private int imgW = 600;
    private LinearLayout layout_other;
    private AbnormalReportInfo info;
    private String fileName1 ="";
    private String fileName2= "";
    private String fileName3 = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void setContentView() {
        setContentView(R.layout.activity_unusual);
        initConfig();
        init();
    }

    @Override
    protected void initViews() {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        tv_shiping_order_num = (TextView) findViewById(R.id.ic_shiping_order_num).findViewById(R.id.tv_name);
        tv_shiping_order_goid = (TextView) findViewById(R.id.ic_shiping_order_goid).findViewById(R.id.tv_name);
        tv_send_station = (TextView) findViewById(R.id.ic_send_station).findViewById(R.id.tv_name);
//        tv_end_address = (TextView) findViewById(R.id.ic_end_address).findViewById(R.id.tv_name);
        tv_custom_name = (TextView) findViewById(R.id.ic_custom_name).findViewById(R.id.tv_name);
        tv_custom_contact = (TextView) findViewById(R.id.ic_custom_contact).findViewById(R.id.tv_name);
        tv_custom_tel = (TextView) findViewById(R.id.ic_custom_tel).findViewById(R.id.tv_name);
        tv_receipt_name = (TextView) findViewById(R.id.ic_receipt_name).findViewById(R.id.tv_name);
        tv_receipt_tel = (TextView) findViewById(R.id.ic_receipt_tel).findViewById(R.id.tv_name);
        tv_end_mechanism = (TextView) findViewById(R.id.ic_end_mechanism).findViewById(R.id.tv_name);
        tv_goods_name = (TextView) findViewById(R.id.ic_goods).findViewById(R.id.tv_left);
        tv_goods_num = (TextView) findViewById(R.id.ic_goods).findViewById(R.id.tv_right);
        tv_goods_weight = (TextView) findViewById(R.id.ic_goodsWV).findViewById(R.id.tv_left);
        tv_goods_vol = (TextView) findViewById(R.id.ic_goodsWV).findViewById(R.id.tv_right);
        tv_shipping_order_state = (TextView) findViewById(R.id.ic_shipping_order_state).findViewById(R.id.tv_left);
        tv_is_recept = (TextView) findViewById(R.id.ic_shipping_order_state).findViewById(R.id.tv_right);
        tv_remarks = (TextView) findViewById(R.id.ic_remarks).findViewById(R.id.tv_name);
        tv_send_mechanism= (TextView) findViewById(R.id.ic_send_mechanism).findViewById(R.id.tv_name);
        btn_edit = (Button) findViewById(R.id.btn_edit);
        iv_uploading1 = ((ImageView) findViewById(R.id.iv_uploading1));
        iv_uploading2 = ((ImageView) findViewById(R.id.iv_uploading2));
        iv_uploading3 = ((ImageView) findViewById(R.id.iv_uploading3));
        iv_uploading2.setVisibility(View.GONE);
        iv_uploading3.setVisibility(View.GONE);
        ed_other= (EditText) findViewById(R.id.ed_other);
        ed_number= (EditText) findViewById(R.id.ed_number);
        ed_name= (EditText) findViewById(R.id.ed_name);
        ed_remarks= (EditText) findViewById(R.id.ed_remarks);
        layout_other= (LinearLayout) findViewById(R.id.layout_other);
        layout_other.setVisibility(View.GONE);
        sp_identity = ((Spinner) findViewById(R.id.sp_identity));
        sp_reson = ((Spinner) findViewById(R.id.sp_reson));

    }

    @Override
    protected void initData() {
        mContext = this;
//        setSupportActionBar(toolbar);
        toolbar.setTitle("异常上报");
        mIntent = getIntent();
        ls_map = new ArrayList<>();
        fileName1="";
        fileName2="";
        fileName3="";
        shippingOrder = (ShippingOrderInfo) mIntent.getExtras().get(
                "shippingOrder");
        setData(shippingOrder);

    }

    @Override
    protected void initEvents() {
        iv_uploading1.setOnClickListener(new mOnClick());
        iv_uploading2.setOnClickListener(new mOnClick());
        iv_uploading3.setOnClickListener(new mOnClick());
        btn_edit.setOnClickListener(new mOnClick());
        toolbar.setNavigationOnClickListener(new mOnClick());
        sp_identity.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                                       int arg2, long arg3) {
                SpinnerInfo spinnerInfo = (SpinnerInfo) sp_identity.getSelectedItem();
                type = spinnerInfo.getId();
                if (type.equals("1")) {
                    BaseSpinnerAdapter Adapter2 = new BaseSpinnerAdapter(mContext, ls2);
                    sp_reson.setAdapter(Adapter2);
                } else if (type.equals("2")) {
                    BaseSpinnerAdapter Adapter2 = new BaseSpinnerAdapter(mContext, ls3);
                    sp_reson.setAdapter(Adapter2);
                }


            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub

            }
        });

        sp_reson.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                                       int arg2, long arg3) {

                SpinnerInfo spinnerInfo2 = (SpinnerInfo) sp_reson.getSelectedItem();
                String string = spinnerInfo2.getText();
                if (string.equals("其它")) {
                    layout_other.setVisibility(View.VISIBLE);

                } else {
                    layout_other.setVisibility(View.GONE);

                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub

            }
        });
    }

    private void setData(ShippingOrderInfo shippingOrderInfo) {
        iv_uploading1.getLayoutParams().height = (ScreenUtils
                .getScreenWidth(mContext) / 3);
        iv_uploading1.getLayoutParams().width = (ScreenUtils
                .getScreenWidth(mContext) / 3);
        iv_uploading2.getLayoutParams().height = (ScreenUtils
                .getScreenWidth(mContext) / 3);
        iv_uploading2.getLayoutParams().width = (ScreenUtils
                .getScreenWidth(mContext) / 3);
        iv_uploading3.getLayoutParams().height = (ScreenUtils
                .getScreenWidth(mContext) / 3);
        iv_uploading3.getLayoutParams().width = (ScreenUtils
                .getScreenWidth(mContext) / 3);
        tv_shiping_order_num.setText("货运编号:" + "    " + shippingOrderInfo.getShiping_order_num());
        tv_shiping_order_goid.setText("出货订单号:" + "    " + shippingOrderInfo.getShiping_order_goid());
        tv_send_station.setText("起运位置:" + "    " + shippingOrderInfo.getSend_station());
//        tv_end_address.setText("终到位置:" + "    " + shippingOrderInfo.getEnd_address());
        tv_custom_name.setText("发货客户名称:" + "    " + shippingOrderInfo.getCustom_name());
        tv_custom_contact.setText("发货联系人:" + "    " + shippingOrderInfo.getCustom_contact());
        tv_custom_tel.setText("发货客户电话:" + "    " + shippingOrderInfo.getCustom_tel());
        tv_receipt_name.setText("收货客户名称:" + "    " + shippingOrderInfo.getReceipt_name());
        tv_receipt_tel.setText("收货客户电话:" + "    " + shippingOrderInfo.getReceipt_tel());
        tv_end_mechanism.setText("收货客户地址:" + "    " + shippingOrderInfo.getEnd_mechanism());
        tv_goods_name.setText("货物名称:" + "    " + shippingOrderInfo.getGoods_name());
        tv_goods_num.setText("总件数:" + "    " + shippingOrderInfo.getGoods_num());
        tv_goods_weight.setText("总重量:" + "    " + shippingOrderInfo.getGoods_weight() + "kg");
        tv_goods_vol.setText("总体积:" + "    " + shippingOrderInfo.getGoods_vol() + "m³");
        tv_send_mechanism.setText("受理机构:" + "    " + shippingOrderInfo.getSend_mechanism());
        //订单状态
        state = String.valueOf(shippingOrderInfo.getShipping_order_state());

            if (state.equals("0")) {
                tv_shipping_order_state.setText("运单状态:    未出库");
                btn_edit.setText("上    报");
                btn_edit.setVisibility(View.VISIBLE);
            } else if (state.equals("1")) {
                tv_shipping_order_state.setText("运单状态:分配订单");
                btn_edit.setText("上    报");
                btn_edit.setVisibility(View.VISIBLE);
            } else if (state.equals("2")) {
                tv_shipping_order_state.setText("运单状态:司机接单");
                btn_edit.setText("上    报");
                btn_edit.setVisibility(View.VISIBLE);
            } else if (state.equals("3")) {
                tv_shipping_order_state.setText("运单状态:电子围栏签收");
                btn_edit.setVisibility(View.VISIBLE);
                btn_edit.setText("上    报");
            } else if (state.equals("4")) {
                tv_shipping_order_state.setText("运单状态:实际签收");
                btn_edit.setVisibility(View.VISIBLE);
                btn_edit.setText("上    报");

            }

        tv_is_recept.setText("回单份数:" + "    " + shippingOrderInfo.getIs_recept());
        tv_remarks.setText("发货备注:" + "    " + shippingOrderInfo.getRemarks());
        ed_name.setText(MyApplication.getUserInfo().getRealName());
        ArrayList ls = new ArrayList();
        ls.add(new SpinnerInfo("1", "货物异常"));
        ls.add(new SpinnerInfo("2", "客户异常"));
        ls2 = new ArrayList();
        ls2.add(new SpinnerInfo("1", "外好内部破损"));
        ls2.add(new SpinnerInfo("2", "外好内部挤压"));
        ls2.add(new SpinnerInfo("3", "外好内部变形"));
        ls2.add(new SpinnerInfo("4", "外好内部渗漏"));
        ls2.add(new SpinnerInfo("5", "外好内部污染"));
        ls2.add(new SpinnerInfo("6", "外好内部短少"));
        ls2.add(new SpinnerInfo("7", "外包装破损"));
        ls2.add(new SpinnerInfo("8", "外包装挤压"));
        ls2.add(new SpinnerInfo("9", "外包装变形"));
        ls2.add(new SpinnerInfo("10", "外包装渗漏"));
        ls2.add(new SpinnerInfo("11", "外包装污染"));
        ls2.add(new SpinnerInfo("12", "外包装短少"));
        ls2.add(new SpinnerInfo("13", "整箱少货"));
        ls2.add(new SpinnerInfo("14", "无回单"));
        ls2.add(new SpinnerInfo("15", "其它"));

        ls3 = new ArrayList();
        ls3.add(new SpinnerInfo("1", "客户电话无人接听"));
        ls3.add(new SpinnerInfo("2", "客户电话关机"));
        ls3.add(new SpinnerInfo("3", "客户电话停机"));
        ls3.add(new SpinnerInfo("4", "客户电话联系不上"));
        ls3.add(new SpinnerInfo("5", "客户不方便收货"));
        ls3.add(new SpinnerInfo("6", "客户出差等通知收货"));
        ls3.add(new SpinnerInfo("7", "其它"));

        BaseSpinnerAdapter Adapter = new BaseSpinnerAdapter(mContext, ls);
        sp_identity.setAdapter(Adapter);
        BaseSpinnerAdapter Adapter2 = new BaseSpinnerAdapter(mContext, ls2);
        sp_reson.setAdapter(Adapter2);

    }

    /**
     * Created by Wangzhiqiang on 2015/11/19.
     * button的点击方法
     */
    class mOnClick implements View.OnClickListener {


        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            switch (v.getId()) {
                case R.id.btn_edit:

                    sendData();

                    break;

                case R.id.iv_uploading1:

                    GalleryFinal.openCamera(REQUEST_CODE_CAMERA, new GalleryFinal.OnHanlderResultCallback() {
                        @Override
                        public void onHanlderSuccess(int reqeustCode, List<PhotoInfo> resultList) {
                            path = resultList.get(0).getPhotoPath().toString();
                            DisplayImageOptions options = new DisplayImageOptions.Builder()
                                    .showImageOnFail(R.drawable.ic_gf_default_photo)
                                    .showImageForEmptyUri(R.drawable.ic_gf_default_photo)
                                    .showImageOnLoading(R.drawable.ic_gf_default_photo).build();
                            com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage("file:/" + path, iv_uploading1, options);
                            iv_uploading2.setVisibility(View.VISIBLE);

                            if (!isNull(path)) {
                                fileName1 = shippingOrder.getShiping_order_num().trim() + "--" +DateUtil.getFileName();
                                uploadPhotos(path, fileName1);

                            }
                        }

                        @Override
                        public void onHanlderFailure(int requestCode, String errorMsg) {
                            T.showShort(getApplicationContext(), errorMsg);
                            Log.e("onHanlderFailure", "");
                        }
                    });
                    break;
                case R.id.iv_uploading2:
                    GalleryFinal.openCamera(REQUEST_CODE_CAMERA, new GalleryFinal.OnHanlderResultCallback() {
                        @Override
                        public void onHanlderSuccess(int reqeustCode, List<PhotoInfo> resultList) {
                            path = resultList.get(0).getPhotoPath().toString();
                            DisplayImageOptions options = new DisplayImageOptions.Builder()
                                    .showImageOnFail(R.drawable.ic_gf_default_photo)
                                    .showImageForEmptyUri(R.drawable.ic_gf_default_photo)
                                    .showImageOnLoading(R.drawable.ic_gf_default_photo).build();
                            com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage("file:/" + path, iv_uploading2, options);
                            iv_uploading3.setVisibility(View.VISIBLE);

                            if (!isNull(path)) {
                                fileName2 = shippingOrder.getShiping_order_num().trim() + "--" +DateUtil.getFileName();
                                uploadPhotos(path,fileName2);

                            }
                        }

                        @Override
                        public void onHanlderFailure(int requestCode, String errorMsg) {
                            T.showShort(getApplicationContext(), errorMsg);
                            Log.e("onHanlderFailure", "");
                        }
                    });

                    break;
                case R.id.iv_uploading3:
                    GalleryFinal.openCamera(REQUEST_CODE_CAMERA, new GalleryFinal.OnHanlderResultCallback() {
                        @Override
                        public void onHanlderSuccess(int reqeustCode, List<PhotoInfo> resultList) {
                            path = resultList.get(0).getPhotoPath().toString();
                            DisplayImageOptions options = new DisplayImageOptions.Builder()
                                    .showImageOnFail(R.drawable.ic_gf_default_photo)
                                    .showImageForEmptyUri(R.drawable.ic_gf_default_photo)
                                    .showImageOnLoading(R.drawable.ic_gf_default_photo).build();
                            com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage("file:/" + path, iv_uploading3, options);
                            if (!isNull(path)) {
                                fileName3 = shippingOrder.getShiping_order_num().trim() + "--" +DateUtil.getFileName();
                                uploadPhotos(path, fileName3);

                            }
                        }

                        @Override
                        public void onHanlderFailure(int requestCode, String errorMsg) {
                            T.showShort(getApplicationContext(), errorMsg);
                            Log.e("onHanlderFailure", "");
                        }
                    });
                    break;
                default:
                    finish();
                    break;
            }
        }
    }
    private void uploadPhotos(String path, String fileName){

        Bitmap bitmap = null;
        File file = new File(path);
        if (file.exists()) {
            try {
                FileInputStream fis = new FileInputStream(file);
                bitmap = BitmapFactory.decodeStream(fis);
                fis.close();
            } catch (Exception e) {
                e.printStackTrace();
            }

            if (bitmap!=null) {
                bitmap = ToolFor9Ge.zoomImg(bitmap, imgW, imgH);
                FileUtil.getInstance().uploadFile(bitmap, fileName,fileRoot);
            }

            if(bitmap.isRecycled()==false) //如果没有回收
                bitmap.recycle();
        }
    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        //普通签收
        if (resultCode == 1) {
            Intent mIntent = new Intent();
            //设置返回数据
            setResult(1, mIntent);
            finish();
        }
    }


    private void sendData(){
        if (isNull(ed_name)) {
            T.showShort(mContext, "上报人姓名不能为空");
            return;
        }
        if (isNull(ed_number)) {
            T.showShort(mContext, "异常件数不能为空");
            return;
        }

        if (info == null)
            info = new AbnormalReportInfo();
        SpinnerInfo spinnerInfo=(SpinnerInfo)sp_reson.getSelectedItem();
        String str = spinnerInfo.getText();

        if (str.equals("其它")){
            if (isNull(ed_other)) {
                T.showShort(mContext, "其他原因不能为空");
                return;
            }
            info.setAbnormal_message(ed_other.getText().toString().trim());
        }else {
            info.setAbnormal_message(str);
        }
        info.setShiping_order_num(shippingOrder.getShiping_order_num());
        info.setShiping_order_id(shippingOrder.getShiping_order_id());
        info.setAbnormal_num(ed_number.getText().toString().trim());
        info.setAbnormal_name(ed_name.getText().toString().trim());
        info.setAbnormal_remark(ed_remarks.getText().toString().trim());
        SpinnerInfo spinnerInfo1=(SpinnerInfo)sp_identity.getSelectedItem();
        info.setAbnormal_type(spinnerInfo1.getId());
        ReceiveOrderTask signShipOrder = new ReceiveOrderTask();
        signShipOrder.execute(info);
    }
    public class ReceiveOrderTask extends AsyncTask<AbnormalReportInfo, Void, String> {
        //onPreExecute方法用于在执行后台任务前做一些UI操作
        @Override
        protected void onPreExecute() {
            mProgressDialog = ProgressDialog.show(mContext, null, "正在加载中...");
            mProgressDialog.setCancelable(true);
            mProgressDialog.setCanceledOnTouchOutside(false);

        }

        protected String doInBackground(AbnormalReportInfo... params) {
            Map<String, Object> map = new HashMap<>();
            String str = "";
            if (fileName1.equals("")){

            }else if (fileName2.equals("")){
                str = fileName1;
            }else if (fileName3.equals("")){
                str = fileName1+","+fileName2;
            }else {
                str = fileName1+","+fileName2+","+fileName3;
            }
            UserInfo userInfo = MyApplication.getUserInfo();
            map.put("userInfo", userInfo);
            map.put("filenames", str);
            map.put("abnormalReport", params[0]);
            String json = JsonUtil.toJson(map);
            return HttpUtils.doPost(UrlUtils.getInstance().getJavaUrl("appAddAbnromalReportOrder"), "json=" + json);
        }

        @Override
        protected void onPostExecute(final String result) {
            mProgressDialog.dismiss();
            if (isNull(result)) {
                T.showShort(mContext, "连接服务器异常");
            } else {

                if (result.indexOf("errorMsg") > 0) {
                    String errorMsg = JsonUtil.getMsg(result, "errorMsg");
                    T.showShort(mContext, errorMsg);
                } else {
                    FileUtil.getInstance().noUpload();
                    String successMsg = JsonUtil.getMsg(result, "successMsg");
                    T.showShort(mContext, successMsg);
                    Intent mIntent = new Intent();
                    //把返回数据存入Intent
                    mIntent.putExtra("result", 1);
                    //设置返回数据
                    setResult(1, mIntent);
                    finish();
                }
            }
        }

        @Override
        protected void onCancelled() {

        }
    }


    private void initConfig() {
        //配置主题
        //ThemeConfig.CYAN
        ThemeConfig theme = new ThemeConfig.Builder()

                .build();
        //配置功能
        FunctionConfig functionConfig = new FunctionConfig.Builder()
                .setEnableCamera(true)
                .setEnableEdit(true)
                .setEnableCrop(true)
                .setEnableRotate(true)
                .setCropSquare(true)
                .setEnablePreview(false)
                .build();

        //配置imageloader
        ImageLoader imageloader = new UILImageLoader();
        //设置核心配置信息
        CoreConfig coreConfig = new CoreConfig.Builder(getApplicationContext(), imageloader, theme)
                .setDebug(BuildConfig.DEBUG)
                .setFunctionConfig(functionConfig)

                .build();
        GalleryFinal.init(coreConfig);
    }

    private void init() {
        File cacheDir = StorageUtils.getCacheDirectory(getApplicationContext());
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
                .memoryCacheExtraOptions(480, 800) // default = device screen dimensions
                .diskCacheExtraOptions(480, 800, null)
                .threadPoolSize(3) // default
                .threadPriority(Thread.NORM_PRIORITY - 2) // default
                .tasksProcessingOrder(QueueProcessingType.FIFO) // default
                .denyCacheImageMultipleSizesInMemory()
                .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
                .memoryCacheSize(2 * 1024 * 1024)
                .memoryCacheSizePercentage(13) // default
                .diskCache(new UnlimitedDiskCache(cacheDir)) // default
                .diskCacheSize(50 * 1024 * 1024)
                .diskCacheFileCount(100)
                .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
                .imageDownloader(new BaseImageDownloader(getApplicationContext())) // default
                .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
                .writeDebugLogs()
                .build();
        com.nostra13.universalimageloader.core.ImageLoader.getInstance().init(config);
    }


}
